/**
 * 
 */
package com.nh.actionPhone;

import java.util.List;

import net.sf.json.JSONSerializer;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.nh.entity.NgVersion;

/**
 * 项目名称：NotoginsengManage
 * 
 * 类名称：VersionCallAction
 * 
 * 类描述：
 * 
 * 创建人：李兴建
 * 
 * E-mail:lxj08193@163.com
 * 
 * 创建时间：2012-11-12 上午09:41:08
 * 
 * 修改人：李兴建
 * 
 * 修改时间：2012-11-12 上午09:41:08
 * 
 * 修改备注：
 * 
 * @version
 */
public class VersionCallAction extends BasePhoneAction {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */

	public void getVersionInfo() {
		Criteria criteria = this.createCriteria(NgVersion.class);
		criteria.add(Restrictions.eq("state", 1));
		criteria.addOrder(Order.desc("publishTime"));
		criteria.setFirstResult(0);
		criteria.setMaxResults(1);
		List<NgVersion> list = criteria.list();
		if (list.size() > 0) {
			JsonConfig config = new JsonConfig();
			config.setIgnoreDefaultExcludes(false);
			config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
			// 只要设置这个数组，指定过滤哪些字段。
			config.setExcludes(new String[] { "createTime", "publishTime", "downloadCount","state" ,"beanState","createAdmin","customType","state","remark"});
			NgVersion version=list.get(0);
			version.setDownloadAddress(this.getProjectURL()+ version.getDownloadAddress());
			this.writResponse(JSONSerializer.toJSON(version, config).toString());
		} else {
			this.writResponse("没有发布新版本");
		}

	}

}
